import { reactive, ref } from "vue";
import {
  containerList as CONS,
  layoutList as LAYS,
  formList as FORMS
} from "@/views/pageDesign/components/leftRegion/widgetsConfig";
// import { debounce, throttle } from "@/utils";

// 全部数据
export let widgetList = reactive([]);
// 属性
export let selectedId = ref("");
export let selectedWidget = reactive({});

export let bianhua = ref(0);

// 选中属性
export let assignmentWidget = (value) => {
  // console.log(value,"value")
  selectedId.value = value.id;
  Object.assign(selectedWidget, value);
  // console.log(selectedWidget,"selectedWidget");
};

//   暂定-------
// export let assignmentWidget = debounce((value) => {
//   console.log("hhhh");
//   console.log(value);
//   selectedId.value = value.id;
//   Object.assign(selectedWidget, value);
// }, 1000);

// 清空
export let clearWidgetList = () => {
  widgetList.splice(0, widgetList.length);
  Object.keys(selectedWidget).forEach((key) => {
    delete selectedWidget[key];
  });
};

// 删除
export let onClickDelete = (item, index) => {
  item.splice(index, 1);
  Object.keys(selectedWidget).forEach((key) => {
    delete selectedWidget[key];
  });
};

// 查找widgetsConfig配置文件对应需要信息
export let getContainerByType = (typeName) => {
  let allWidgets = [...CONS, ...LAYS,...FORMS];
  let foundCon = null;
  allWidgets.forEach((con) => {
    if (!!con.category && !!con.type && con.type == typeName) {
      foundCon = con;
    }
  });
  return foundCon;
};

export let hh = (value) => {
  // console.log(value, "value");
  bianhua.value == value;
};
